package 代码记录.校招笔试真题.笔试真题_2022.欧科云链12月;

import java.util.*;

/**
 * @author zx
 * @create 2022-11-30 16:12
 */
public class Test1 {
    List<Integer> list = new ArrayList<>();
    public int kthSmallest(TreeNode root, int k) {
        inOrder(root);
        Collections.sort(list);
        int res = 0;
        for(int i = 0;i < k;i++){
            res = list.get(i);
        }
        return res;
    }
    private void inOrder(TreeNode root){
        if(root == null){
            return;
        }
        inOrder(root.left);
        list.add(root.val);
        inOrder(root.right);
    }
    static class TreeNode {
        TreeNode left;
        TreeNode right;
        int val;
    }
}
